package WaitNotify.demo3;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-25
 * Time: 17:47
 */
//邮递员也是一个线程,用来送信
public class Postman extends Thread {
    private int id;
    private String mail;

    public Postman(int id, String mail) {
        this.id = id;
        this.mail = mail;
    }

    @Override
    public void run() {
        System.out.println("邮递员送信");
        //根据ID获取自己的邮箱格子
        GuardedObject guardedObject = MailBox.getGuardedObject(id);
        System.out.printf("送信的信息id : %d,mail : %s\n",guardedObject.getId(),mail);
        //将信放进去
        guardedObject.complete(mail);
    }
}
